var parkId = "";
var parkName = "";


$(document).ready(function () {
    initData();
});

function initData(parkId) {
    parkId = $("#parkId").val();
    parkName = $("#parkName").val();
    vehicleFlow(parkId, name);//车流折线趋势图
    vehicleFlow2(parkId, name);//订单金额 时间检索 折线趋势图
    vehicleFlow3(parkId, name);
    vehicleFlow4(parkId, name);
    vehicleFlow5(parkId, name);
}


function vehicleFlow(parkId, name) {
    var myChart = echarts.init(document.getElementById("box1"));
    myChart.showLoading();
    // option 里面的内容基本涵盖你要画的图表的所有内容
    $.ajax({
        url: "/front/countOrderByPark",
        dataType: "json",
        data: {"parkId": parkId},
        type: "post",
        success: function (data) {
            var ress = [];
            $.each(data.data, function (key, vale) {
                ress.push({
                    value: vale.axis,
                });
            });
            myChart.hideLoading();
            myChart.setOption({
                title: {
                    text: name + '当日车流量',
                    x: 'center'
                },
                // legend: {
                //     data:['收入']
                // },
                tooltip: {
                    trigger: 'axis'
                },
                calculable: true,
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: ress
                },
                yAxis: {       //直角坐标系 grid 中的 y 轴
                    type: 'value'
                },
                series: [{
                    // 根据名字对应到相应的系列
                    name: '车流量',
                    type: 'line',
                    stack: '总量',
                    areaStyle: {},
                    data: function () {
                        var res = [];
                        $.each(data.data, function (key, vale) {
                            res.push({
                                value: vale.value,
                            });
                        });
                        return res;
                    }()
                }]


            })
        }
    })
}

function vehicleFlow2(parkId, name) {
    var myChart = echarts.init(document.getElementById("box2"));
    myChart.showLoading();
    // option 里面的内容基本涵盖你要画的图表的所有内容
    $.ajax({
        url: "/front/countPassRecordByPark",
        dataType: "json",
        data: {"parkId": parkId},
        type: "post",
        success: function (data) {
            var ress = [];
            $.each(data.data, function (key, vale) {
                ress.push({
                    value: vale.axis,
                });
            });

            myChart.hideLoading();
            myChart.setOption({
                title: {
                    text: name + '当日车流量',
                    x: 'center'
                },
                // legend: {
                //     data:['收入']
                // },
                tooltip: {
                    trigger: 'axis'
                },
                calculable: true,
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: ress//不可写function
                },
                yAxis: {       //直角坐标系 grid 中的 y 轴
                    type: 'value'
                },
                series: [{
                    // 根据名字对应到相应的系列
                    name: '车流量',
                    type: 'line',
                    stack: '总量',
                    areaStyle: {},
                    data: function () {
                        var res = [];
                        $.each(data.data, function (key, vale) {
                            res.push({
                                value: vale.value,
                            });
                        });
                        return res;
                    }()
                }]


            })
        }
    })
}


// 历史车流量
function vehicleFlow3(parkId, name) {
    let accountId = 'e541358919f0050ec2e46f83d2d35df6';
    var myChart = echarts.init(document.getElementById("box3"));
    myChart.showLoading();
    // option 里面的内容基本涵盖你要画的图表的所有内容
    $.ajax({
        url: "/front/getHistorys",
        dataType: "json",
        data: {"accountId": accountId},
        type: "post",
        success: function (data) {
            var ress = [];
            $.each(data.data, function (key, vale) {
                ress.push({
                    value: vale.axis,
                });
            });

            myChart.hideLoading();
            myChart.setOption({
                title: {
                    text: name + '历史车流量',
                    x: 'center'
                },
                tooltip: {
                    trigger: 'axis'
                },
                calculable: true,
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: ress//不可写function
                },
                yAxis: {       //直角坐标系 grid 中的 y 轴
                    type: 'value'
                },
                series: [{
                    // 根据名字对应到相应的系列
                    name: '历史车流量',
                    type: 'line',
                    areaStyle: {},
                    data: function () {
                        var res = [];
                        $.each(data.data, function (key, vale) {
                            res.push({
                                value: vale.value,
                            });
                        });
                        return res;
                    }()
                }]


            })
        }
    })
}

// 历史订单量
function vehicleFlow4(parkId, name) {
    let accountId = 'cab347197a9c30b945b0d345455d6182';
    var myChart = echarts.init(document.getElementById("box4"));
    myChart.showLoading();
    // option 里面的内容基本涵盖你要画的图表的所有内容
    $.ajax({
        url: "/front/getHistoryOrder",
        dataType: "json",
        data: {"accountId": accountId},
        type: "post",
        success: function (data) {
            var ress = [];
            $.each(data.data, function (key, vale) {
                ress.push({
                    value: vale.axis,
                });
            });

            myChart.hideLoading();
            myChart.setOption({
                title: {
                    text: name + '历史订单量',
                    x: 'center'
                },
                tooltip: {
                    trigger: 'axis'
                },
                calculable: true,
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: ress//不可写function
                },
                yAxis: {       //直角坐标系 grid 中的 y 轴
                    type: 'value'
                },
                series: [{
                    // 根据名字对应到相应的系列
                    name: '历史订单量',
                    type: 'line',
                    areaStyle: {},
                    data: function () {
                        var res = [];
                        $.each(data.data, function (key, vale) {
                            res.push({
                                value: vale.value,
                            });
                        });
                        return res;
                    }()
                }]


            })
        }
    })
}

//各停车场车流量统计
function vehicleFlow5(parkId, name) {
    let accountId = 'e541358919f0050ec2e46f83d2d35df6';
    let myChart = echarts.init(document.getElementById('box5'));
    myChart.showLoading();
    $.ajax({
        url: "/front/getTodays",
        dataType: "json",
        data: {"accountId": accountId},
        type: "post",
        success: function (data) {

            console.log(data.data);

            myChart.hideLoading();
            myChart.setOption({
                title: {
                    text: '各停车场车流量统计',
                    x: 'center'
                },
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {//图例
                    orient: 'vertical',
                    left: 'left',
                    data: function () {
                        let res = []
                        $.each(data.data, function (key, vale) {
                            res.push({
                                value: vale.axis,
                            });
                        });
                        return res;
                    }()
                },
                series: [
                    {
                        name: '流量统计',
                        type: 'pie',
                        radius: '55%',
                        data: function () {
                            let res = [];
                            $.each(data.data, function (key, vale) {
                                res.push({
                                    value: vale.value,
                                    name: vale.axis,
                                });
                            });
                            return res;
                        }()
                    }
                ]
            })
        }

    })
}